package algorithm;

/**
 * 插入排序
 */
public class InsertionSort {
    public static void main(String[] args) {
        int[] arr = new int[10];
        for (int i = 0; i < arr.length; i++) {
            arr[i]=(int)(Math.random()*100+1);
            System.out.print(arr[i]+" ");
        }
        System.out.println();
        for (int i = 1; i < arr.length; i++) {
            for (int j = i-1; j >= 0; j--) {
                if (arr[j]>arr[j+1]){
                    int temp =arr[j];
                    arr[j] =arr[j+1];
                    arr[j+1] = temp;
                }else {
                    break;
                }
            }
            for (int k : arr) {
                System.out.print(k+" ");
            }
            System.out.println();

        }
    }

}
